#!/usr/bin/env coffee

"""
  tucao.in
  about most value discuss!
"""

express = require('express')
app = module.exports = express.createServer()
require './extends'
tucao = require('./tucao')
connect = require './connect'
RedisStore = require('connect-redis')(express)

#Configuration
app.configure () ->
  app.set('views', __dirname + '/views')
  app.set('view engine', 'coffee')
  app.register('.coffee', require('coffeekup').adapters.express)
  #app.set('view options', { layout: false })

  #RedisStore = require('connect-redis')(express)
  app.use(express.cookieParser())
  app.use(express.favicon())
  app.use express.session
    key: "tucao.in"
    secret: "tucaoin"
    store: new RedisStore
    cookie:
      path: "/"
      httpOnly: true
      #maxAge: false
  #app.use(express.session({key: "tucao.in", secret: "tucaoin"}))
  app.use(express.bodyParser())
  app.use(express.methodOverride())
  app.use(app.router)
  app.use(express.static(__dirname + '/public'))


app.configure 'development', ()->
  app.use(express.errorHandler({ dumpExceptions: true, showStack: true }))


app.configure 'production', ()->
  app.use(express.errorHandler())
  model = require './model'
  model.client.select 1 #Movie Main database on database index 1
  


tucao app
connect app

app.listen 7000
console.log "Express server listening on port %d in %s mode", app.address().port, app.settings.env
